package com.xnyzc.lhy.mis.controller.cmsapi.user;

import com.xnyzc.lhy.common.entity.Rv;
import com.xnyzc.lhy.common.exception.PangException;
import com.xnyzc.lhy.common.penum.EErrorCode;
import com.xnyzc.lhy.common.util.CheckUtil;
import com.xnyzc.lhy.common.util.TokenUtil;
import com.xnyzc.lhy.mis.entity.param.cms.user.CmsOaCUserImportParam;
import com.xnyzc.lhy.mis.entity.result.cms.user.CmsOaCUserImport;
import com.xnyzc.lhy.mis.service.cms.user.ICmsOaCUserImportService;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Description 导入
 * @Author zhuyubin
 * @Date 2019-08-28 19:41
 **/
@RestController
@RequestMapping(value = "cmsapi/cmsOaCUserImport")
public class CmsOaCUserImportController {

    @Autowired
    private ICmsOaCUserImportService iCmsOaCUserImportService;

    /**
     * 导入
     * @param cmsOaCUserImportParam 入参
     * @return
     */
    @PostMapping(value = "userImport")
    public Rv userImport(@RequestBody CmsOaCUserImportParam cmsOaCUserImportParam){
        long sysUserId = TokenUtil.getTokenUserId();
        String tag = TokenUtil.getTag();
        if (CheckUtil.objIsEmpty(tag)){
            throw PangException.create(EErrorCode.missingAuthArgs);
        }
        List<CmsOaCUserImport> cmsOaCUserImportList = cmsOaCUserImportParam.getCmsOaCUserImportList();
        if (CheckUtil.objIsEmpty(cmsOaCUserImportList)){
            throw PangException.create(EErrorCode.missingArg);
        }
        return Rv.wrap(iCmsOaCUserImportService.userImport(sysUserId, tag, cmsOaCUserImportList));
    }

    /**
     * 获取模板url
     * @return
     */
    @GetMapping(value = "getUserImportFile")
    public Rv getUserImportFile(
            @ApiParam(name = "type", value = "类型", required = true) Integer type){
        String tag = TokenUtil.getTag();
        if (CheckUtil.objIsEmpty(tag)){
            throw PangException.create(EErrorCode.missingAuthArgs);
        }
        return Rv.wrap(iCmsOaCUserImportService.getUserImportFile(tag, type));
    }
}
